
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 09/11/2010 00:24:06
-- Generated from EDMX file: C:\code\MiniBug2\MiniBug\Entity\MSSQLModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [minibug];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Bug_Bug]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Bug] DROP CONSTRAINT [FK_Bug_Bug];
GO
IF OBJECT_ID(N'[dbo].[FK_Bug_Component]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Bug] DROP CONSTRAINT [FK_Bug_Component];
GO
IF OBJECT_ID(N'[dbo].[FK_Bug_Priority]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Bug] DROP CONSTRAINT [FK_Bug_Priority];
GO
IF OBJECT_ID(N'[dbo].[FK_Bug_Project]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Bug] DROP CONSTRAINT [FK_Bug_Project];
GO
IF OBJECT_ID(N'[dbo].[FK_BugAttachment_Bug]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BugAttachment] DROP CONSTRAINT [FK_BugAttachment_Bug];
GO
IF OBJECT_ID(N'[dbo].[FK_BugHistory_Bug]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BugHistory] DROP CONSTRAINT [FK_BugHistory_Bug];
GO
IF OBJECT_ID(N'[dbo].[FK_BugTag_Bug]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BugTag] DROP CONSTRAINT [FK_BugTag_Bug];
GO
IF OBJECT_ID(N'[dbo].[FK_BugHistory_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BugHistory] DROP CONSTRAINT [FK_BugHistory_User];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectRelease_Project]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectRelease] DROP CONSTRAINT [FK_ProjectRelease_Project];
GO
IF OBJECT_ID(N'[dbo].[FK_BugOwner_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Bug] DROP CONSTRAINT [FK_BugOwner_User];
GO
IF OBJECT_ID(N'[dbo].[FK_BugAssignedTo_Bug]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Bug] DROP CONSTRAINT [FK_BugAssignedTo_Bug];
GO
IF OBJECT_ID(N'[dbo].[FK_BugVote]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Vote] DROP CONSTRAINT [FK_BugVote];
GO
IF OBJECT_ID(N'[dbo].[FK_UserUserOption]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserOptionSet] DROP CONSTRAINT [FK_UserUserOption];
GO
IF OBJECT_ID(N'[dbo].[FK_BugWorkingHours]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkingHours] DROP CONSTRAINT [FK_BugWorkingHours];
GO
IF OBJECT_ID(N'[dbo].[FK_UserWorkingHours]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WorkingHours] DROP CONSTRAINT [FK_UserWorkingHours];
GO
IF OBJECT_ID(N'[dbo].[FK_CalendarCalendarExceptions]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CalendarExceptions] DROP CONSTRAINT [FK_CalendarCalendarExceptions];
GO
IF OBJECT_ID(N'[dbo].[FK_CalendarUserOption]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserOptionSet] DROP CONSTRAINT [FK_CalendarUserOption];
GO
IF OBJECT_ID(N'[dbo].[FK_UserLastEditedBy]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Bug] DROP CONSTRAINT [FK_UserLastEditedBy];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Bug]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Bug];
GO
IF OBJECT_ID(N'[dbo].[BugAttachment]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BugAttachment];
GO
IF OBJECT_ID(N'[dbo].[BugHistory]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BugHistory];
GO
IF OBJECT_ID(N'[dbo].[BugTag]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BugTag];
GO
IF OBJECT_ID(N'[dbo].[Component]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Component];
GO
IF OBJECT_ID(N'[dbo].[Priority]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Priority];
GO
IF OBJECT_ID(N'[dbo].[Project]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Project];
GO
IF OBJECT_ID(N'[dbo].[ProjectRelease]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectRelease];
GO
IF OBJECT_ID(N'[dbo].[User]', 'U') IS NOT NULL
    DROP TABLE [dbo].[User];
GO
IF OBJECT_ID(N'[dbo].[Vote]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Vote];
GO
IF OBJECT_ID(N'[dbo].[UserOptionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserOptionSet];
GO
IF OBJECT_ID(N'[dbo].[WorkingHours]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkingHours];
GO
IF OBJECT_ID(N'[dbo].[Calendar]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Calendar];
GO
IF OBJECT_ID(N'[dbo].[CalendarExceptions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CalendarExceptions];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Bug'
CREATE TABLE [dbo].[Bug] (
    [idBug] int IDENTITY(1,1) NOT NULL,
    [idBugParent] int  NULL,
    [Title] nvarchar(150)  NOT NULL,
    [Description] varchar(max)  NULL,
    [OpenDate] datetime  NOT NULL,
    [CloseDate] datetime  NULL,
    [idProject] int  NOT NULL,
    [idCategory] int  NULL,
    [Status] int  NULL,
    [idPriority] int  NOT NULL,
    [idOwner] int  NOT NULL,
    [EstimatedTime] datetime  NULL,
    [ActualTime] datetime  NULL,
    [DueDate] datetime  NULL,
    [idComponent] int  NULL,
    [Number] int  NOT NULL,
    [idAssignedTo] int  NULL,
    [AdjustmentFactor] decimal(18,0)  NOT NULL,
    [EstimatedAjusted] decimal(18,0)  NOT NULL,
    [idLastEditedBy] int  NOT NULL,
    [LastEditedAt] datetime  NOT NULL,
    [Views] int  NOT NULL
);
GO

-- Creating table 'BugAttachment'
CREATE TABLE [dbo].[BugAttachment] (
    [idBugAttachment] int IDENTITY(1,1) NOT NULL,
    [idBug] int  NOT NULL,
    [data] varbinary(max)  NOT NULL
);
GO

-- Creating table 'BugHistory'
CREATE TABLE [dbo].[BugHistory] (
    [idBugHistory] int IDENTITY(1,1) NOT NULL,
    [idBug] int  NOT NULL,
    [ChangeDate] datetime  NULL,
    [Description] nvarchar(max)  NULL,
    [idUser] int  NULL
);
GO

-- Creating table 'BugTag'
CREATE TABLE [dbo].[BugTag] (
    [idBugTag] int IDENTITY(1,1) NOT NULL,
    [idBug] int  NOT NULL,
    [tag] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Component'
CREATE TABLE [dbo].[Component] (
    [idComponent] int IDENTITY(1,1) NOT NULL,
    [Label] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Priority'
CREATE TABLE [dbo].[Priority] (
    [idPriority] int IDENTITY(1,1) NOT NULL,
    [Label] nvarchar(50)  NOT NULL,
    [Number] int  NOT NULL
);
GO

-- Creating table 'Project'
CREATE TABLE [dbo].[Project] (
    [idProject] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(150)  NOT NULL
);
GO

-- Creating table 'ProjectRelease'
CREATE TABLE [dbo].[ProjectRelease] (
    [idProjectRelease] int IDENTITY(1,1) NOT NULL,
    [idProject] int  NOT NULL,
    [release] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'User'
CREATE TABLE [dbo].[User] (
    [idUser] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Login] nvarchar(50)  NOT NULL,
    [Password] nvarchar(50)  NOT NULL,
    [Email] nvarchar(50)  NULL,
    [isVirtual] bit  NOT NULL,
    [isAdmin] bit  NOT NULL
);
GO

-- Creating table 'Vote'
CREATE TABLE [dbo].[Vote] (
    [IdVote] int IDENTITY(1,1) NOT NULL,
    [idUser] int  NOT NULL,
    [Comments] nvarchar(max)  NOT NULL,
    [idBug] int  NOT NULL
);
GO

-- Creating table 'UserOptionSet'
CREATE TABLE [dbo].[UserOptionSet] (
    [IdUserOption] int IDENTITY(1,1) NOT NULL,
    [Language] nvarchar(max)  NOT NULL,
    [PageSize] nvarchar(max)  NOT NULL,
    [idUser] int  NOT NULL,
    [idCalendar] int  NOT NULL
);
GO

-- Creating table 'WorkingHours'
CREATE TABLE [dbo].[WorkingHours] (
    [IdWorkingHours] int IDENTITY(1,1) NOT NULL,
    [idBug] int  NOT NULL,
    [idUser] int  NOT NULL,
    [Start] datetime  NOT NULL,
    [Finish] datetime  NOT NULL,
    [Date] datetime  NOT NULL
);
GO

-- Creating table 'Calendar'
CREATE TABLE [dbo].[Calendar] (
    [IdCalendar] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Start] datetime  NOT NULL,
    [Finish] datetime  NULL
);
GO

-- Creating table 'CalendarExceptions'
CREATE TABLE [dbo].[CalendarExceptions] (
    [IdCalendarException] int IDENTITY(1,1) NOT NULL,
    [idCalendar] int  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Start] datetime  NOT NULL,
    [Finish] datetime  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [idBug] in table 'Bug'
ALTER TABLE [dbo].[Bug]
ADD CONSTRAINT [PK_Bug]
    PRIMARY KEY CLUSTERED ([idBug] ASC);
GO

-- Creating primary key on [idBugAttachment] in table 'BugAttachment'
ALTER TABLE [dbo].[BugAttachment]
ADD CONSTRAINT [PK_BugAttachment]
    PRIMARY KEY CLUSTERED ([idBugAttachment] ASC);
GO

-- Creating primary key on [idBugHistory] in table 'BugHistory'
ALTER TABLE [dbo].[BugHistory]
ADD CONSTRAINT [PK_BugHistory]
    PRIMARY KEY CLUSTERED ([idBugHistory] ASC);
GO

-- Creating primary key on [idBugTag] in table 'BugTag'
ALTER TABLE [dbo].[BugTag]
ADD CONSTRAINT [PK_BugTag]
    PRIMARY KEY CLUSTERED ([idBugTag] ASC);
GO

-- Creating primary key on [idComponent] in table 'Component'
ALTER TABLE [dbo].[Component]
ADD CONSTRAINT [PK_Component]
    PRIMARY KEY CLUSTERED ([idComponent] ASC);
GO

-- Creating primary key on [idPriority] in table 'Priority'
ALTER TABLE [dbo].[Priority]
ADD CONSTRAINT [PK_Priority]
    PRIMARY KEY CLUSTERED ([idPriority] ASC);
GO

-- Creating primary key on [idProject] in table 'Project'
ALTER TABLE [dbo].[Project]
ADD CONSTRAINT [PK_Project]
    PRIMARY KEY CLUSTERED ([idProject] ASC);
GO

-- Creating primary key on [idProjectRelease] in table 'ProjectRelease'
ALTER TABLE [dbo].[ProjectRelease]
ADD CONSTRAINT [PK_ProjectRelease]
    PRIMARY KEY CLUSTERED ([idProjectRelease] ASC);
GO

-- Creating primary key on [idUser] in table 'User'
ALTER TABLE [dbo].[User]
ADD CONSTRAINT [PK_User]
    PRIMARY KEY CLUSTERED ([idUser] ASC);
GO

-- Creating primary key on [IdVote] in table 'Vote'
ALTER TABLE [dbo].[Vote]
ADD CONSTRAINT [PK_Vote]
    PRIMARY KEY CLUSTERED ([IdVote] ASC);
GO

-- Creating primary key on [IdUserOption] in table 'UserOptionSet'
ALTER TABLE [dbo].[UserOptionSet]
ADD CONSTRAINT [PK_UserOptionSet]
    PRIMARY KEY CLUSTERED ([IdUserOption] ASC);
GO

-- Creating primary key on [IdWorkingHours] in table 'WorkingHours'
ALTER TABLE [dbo].[WorkingHours]
ADD CONSTRAINT [PK_WorkingHours]
    PRIMARY KEY CLUSTERED ([IdWorkingHours] ASC);
GO

-- Creating primary key on [IdCalendar] in table 'Calendar'
ALTER TABLE [dbo].[Calendar]
ADD CONSTRAINT [PK_Calendar]
    PRIMARY KEY CLUSTERED ([IdCalendar] ASC);
GO

-- Creating primary key on [IdCalendarException] in table 'CalendarExceptions'
ALTER TABLE [dbo].[CalendarExceptions]
ADD CONSTRAINT [PK_CalendarExceptions]
    PRIMARY KEY CLUSTERED ([IdCalendarException] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [idBugParent] in table 'Bug'
ALTER TABLE [dbo].[Bug]
ADD CONSTRAINT [FK_Bug_Bug]
    FOREIGN KEY ([idBugParent])
    REFERENCES [dbo].[Bug]
        ([idBug])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Bug_Bug'
CREATE INDEX [IX_FK_Bug_Bug]
ON [dbo].[Bug]
    ([idBugParent]);
GO

-- Creating foreign key on [idComponent] in table 'Bug'
ALTER TABLE [dbo].[Bug]
ADD CONSTRAINT [FK_Bug_Component]
    FOREIGN KEY ([idComponent])
    REFERENCES [dbo].[Component]
        ([idComponent])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Bug_Component'
CREATE INDEX [IX_FK_Bug_Component]
ON [dbo].[Bug]
    ([idComponent]);
GO

-- Creating foreign key on [idPriority] in table 'Bug'
ALTER TABLE [dbo].[Bug]
ADD CONSTRAINT [FK_Bug_Priority]
    FOREIGN KEY ([idPriority])
    REFERENCES [dbo].[Priority]
        ([idPriority])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Bug_Priority'
CREATE INDEX [IX_FK_Bug_Priority]
ON [dbo].[Bug]
    ([idPriority]);
GO

-- Creating foreign key on [idProject] in table 'Bug'
ALTER TABLE [dbo].[Bug]
ADD CONSTRAINT [FK_Bug_Project]
    FOREIGN KEY ([idProject])
    REFERENCES [dbo].[Project]
        ([idProject])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Bug_Project'
CREATE INDEX [IX_FK_Bug_Project]
ON [dbo].[Bug]
    ([idProject]);
GO

-- Creating foreign key on [idBug] in table 'BugAttachment'
ALTER TABLE [dbo].[BugAttachment]
ADD CONSTRAINT [FK_BugAttachment_Bug]
    FOREIGN KEY ([idBug])
    REFERENCES [dbo].[Bug]
        ([idBug])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BugAttachment_Bug'
CREATE INDEX [IX_FK_BugAttachment_Bug]
ON [dbo].[BugAttachment]
    ([idBug]);
GO

-- Creating foreign key on [idBug] in table 'BugHistory'
ALTER TABLE [dbo].[BugHistory]
ADD CONSTRAINT [FK_BugHistory_Bug]
    FOREIGN KEY ([idBug])
    REFERENCES [dbo].[Bug]
        ([idBug])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BugHistory_Bug'
CREATE INDEX [IX_FK_BugHistory_Bug]
ON [dbo].[BugHistory]
    ([idBug]);
GO

-- Creating foreign key on [idBug] in table 'BugTag'
ALTER TABLE [dbo].[BugTag]
ADD CONSTRAINT [FK_BugTag_Bug]
    FOREIGN KEY ([idBug])
    REFERENCES [dbo].[Bug]
        ([idBug])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BugTag_Bug'
CREATE INDEX [IX_FK_BugTag_Bug]
ON [dbo].[BugTag]
    ([idBug]);
GO

-- Creating foreign key on [idUser] in table 'BugHistory'
ALTER TABLE [dbo].[BugHistory]
ADD CONSTRAINT [FK_BugHistory_User]
    FOREIGN KEY ([idUser])
    REFERENCES [dbo].[User]
        ([idUser])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BugHistory_User'
CREATE INDEX [IX_FK_BugHistory_User]
ON [dbo].[BugHistory]
    ([idUser]);
GO

-- Creating foreign key on [idProject] in table 'ProjectRelease'
ALTER TABLE [dbo].[ProjectRelease]
ADD CONSTRAINT [FK_ProjectRelease_Project]
    FOREIGN KEY ([idProject])
    REFERENCES [dbo].[Project]
        ([idProject])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectRelease_Project'
CREATE INDEX [IX_FK_ProjectRelease_Project]
ON [dbo].[ProjectRelease]
    ([idProject]);
GO

-- Creating foreign key on [idOwner] in table 'Bug'
ALTER TABLE [dbo].[Bug]
ADD CONSTRAINT [FK_BugOwner_User]
    FOREIGN KEY ([idOwner])
    REFERENCES [dbo].[User]
        ([idUser])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BugOwner_User'
CREATE INDEX [IX_FK_BugOwner_User]
ON [dbo].[Bug]
    ([idOwner]);
GO

-- Creating foreign key on [idAssignedTo] in table 'Bug'
ALTER TABLE [dbo].[Bug]
ADD CONSTRAINT [FK_BugAssignedTo_Bug]
    FOREIGN KEY ([idAssignedTo])
    REFERENCES [dbo].[User]
        ([idUser])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BugAssignedTo_Bug'
CREATE INDEX [IX_FK_BugAssignedTo_Bug]
ON [dbo].[Bug]
    ([idAssignedTo]);
GO

-- Creating foreign key on [idBug] in table 'Vote'
ALTER TABLE [dbo].[Vote]
ADD CONSTRAINT [FK_BugVote]
    FOREIGN KEY ([idBug])
    REFERENCES [dbo].[Bug]
        ([idBug])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BugVote'
CREATE INDEX [IX_FK_BugVote]
ON [dbo].[Vote]
    ([idBug]);
GO

-- Creating foreign key on [idUser] in table 'UserOptionSet'
ALTER TABLE [dbo].[UserOptionSet]
ADD CONSTRAINT [FK_UserUserOption]
    FOREIGN KEY ([idUser])
    REFERENCES [dbo].[User]
        ([idUser])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserUserOption'
CREATE INDEX [IX_FK_UserUserOption]
ON [dbo].[UserOptionSet]
    ([idUser]);
GO

-- Creating foreign key on [idBug] in table 'WorkingHours'
ALTER TABLE [dbo].[WorkingHours]
ADD CONSTRAINT [FK_BugWorkingHours]
    FOREIGN KEY ([idBug])
    REFERENCES [dbo].[Bug]
        ([idBug])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BugWorkingHours'
CREATE INDEX [IX_FK_BugWorkingHours]
ON [dbo].[WorkingHours]
    ([idBug]);
GO

-- Creating foreign key on [idUser] in table 'WorkingHours'
ALTER TABLE [dbo].[WorkingHours]
ADD CONSTRAINT [FK_UserWorkingHours]
    FOREIGN KEY ([idUser])
    REFERENCES [dbo].[User]
        ([idUser])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserWorkingHours'
CREATE INDEX [IX_FK_UserWorkingHours]
ON [dbo].[WorkingHours]
    ([idUser]);
GO

-- Creating foreign key on [idCalendar] in table 'CalendarExceptions'
ALTER TABLE [dbo].[CalendarExceptions]
ADD CONSTRAINT [FK_CalendarCalendarExceptions]
    FOREIGN KEY ([idCalendar])
    REFERENCES [dbo].[Calendar]
        ([IdCalendar])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CalendarCalendarExceptions'
CREATE INDEX [IX_FK_CalendarCalendarExceptions]
ON [dbo].[CalendarExceptions]
    ([idCalendar]);
GO

-- Creating foreign key on [idCalendar] in table 'UserOptionSet'
ALTER TABLE [dbo].[UserOptionSet]
ADD CONSTRAINT [FK_CalendarUserOption]
    FOREIGN KEY ([idCalendar])
    REFERENCES [dbo].[Calendar]
        ([IdCalendar])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CalendarUserOption'
CREATE INDEX [IX_FK_CalendarUserOption]
ON [dbo].[UserOptionSet]
    ([idCalendar]);
GO

-- Creating foreign key on [idLastEditedBy] in table 'Bug'
ALTER TABLE [dbo].[Bug]
ADD CONSTRAINT [FK_UserLastEditedBy]
    FOREIGN KEY ([idLastEditedBy])
    REFERENCES [dbo].[User]
        ([idUser])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserLastEditedBy'
CREATE INDEX [IX_FK_UserLastEditedBy]
ON [dbo].[Bug]
    ([idLastEditedBy]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------